package com.mask.im.business.controller;
import com.mask.im.business.model.dto.AnnouncementDTO;
import com.mask.im.business.model.dto.MailDTO;
import com.mask.im.business.model.entity.AnnouncementDO;
import com.mask.im.business.model.vo.AnnouncementVO;
import com.mask.im.business.common.model.PageResult;
import com.mask.im.business.common.model.RestResponse;
import com.mask.im.business.service.AnnouncementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "公告模块")
@RestController
@CrossOrigin
public class AnnouncementController {

	@Autowired
	private AnnouncementService announcementService;

	@ApiOperation("获取发布公告")
	@GetMapping("/users/announcement")
	public RestResponse<List<AnnouncementDO>> getAnnouncement(){
		return announcementService.getAnnouncement();
	}

	@ApiOperation("获取公告草稿")
	@GetMapping("/admin/draft/announcement")
	public PageResult<AnnouncementDTO> draftAnnouncement(@RequestParam(value = "status",required = false) Integer status,
                                                         @RequestParam(value = "title",required = false) String title){
		return announcementService.draftAnnouncement(title,status);
	}

	@ApiOperation("发布或保存草稿公告")
	@PostMapping("/admin/save/announcement")
	public RestResponse<String> saveAnnouncement(@RequestBody AnnouncementVO announcementVO){
		return announcementService.saveAnnouncement(announcementVO);
	}

	@ApiOperation("获取已发布的公告")
	@GetMapping("/admin/publish/announcement")
	public PageResult<AnnouncementDTO> publishAnnouncement(@RequestParam(value = "publishDate",required = false) String publishDate,
                                                           @RequestParam(value = "title",required = false) String draftTitle){
		return announcementService.publishAnnouncement(publishDate,draftTitle);
	}
	@ApiOperation("删除公告")
	@DeleteMapping("/admin/deleteAnnouncement/{id}")
	public RestResponse<String> deleteAnnouncement(@PathVariable Integer id){
		return announcementService.deleteAnnouncement(id);
	}

	@ApiOperation("根据id获取公告")
	@GetMapping("/users/announcementById/{id}")
	public RestResponse<MailDTO> announcementById(@PathVariable Integer id){
		return announcementService.announcementById(id);
	}
}

